package com.xiaobai.springbootconfig;

import org.springframework.beans.BeansException;
import org.springframework.beans.MutablePropertyValues;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.context.annotation.Configuration;

import java.util.Iterator;

@Configuration
public class MyBeanFactoryPostProcessor implements BeanFactoryPostProcessor {
    @Override
    public void postProcessBeanFactory(ConfigurableListableBeanFactory configurableListableBeanFactory) throws BeansException {
        Iterator<String> beanNamesIterator = configurableListableBeanFactory.getBeanNamesIterator();
        while (beanNamesIterator.hasNext()) {
            String next = beanNamesIterator.next();
            if ("user".equals(next)) {
                BeanDefinition definition = configurableListableBeanFactory.getBeanDefinition(next);
                MutablePropertyValues propertyValues = definition.getPropertyValues();
                System.out.println("修改了值");
                propertyValues.add("name", "小黑");
            }
        }
    }
}
